home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / The Hacks / APLocation / Sources / MacOS_UAppleEvents.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-06-23  |  24.2 KB  |  960 lines

  1. /*==================================================================
  2.     File:        MacOS_UAppleEvents.cpp
  3.     
  4.     Contains:    AppleEvent utility classes.
  5.  
  6.     Written by:    Ed Reed
  7.     
  8.     Copyright:    © 1999 Connectix Corporation
  9. ==================================================================*/
  10.  
  11. #include "MacOS_UAppleEvents.h"
  12.  
  13. #include "MacOS_AppleEventUtils.h"
  14. #include "MacOS_Exceptions.h"
  15. #include "MacOS_Namespaces.h"
  16.  
  17. #ifndef __AEPACKOBJECT__
  18. #include <AEPackObject.h>
  19. #endif
  20.  
  21. #include <cstring>
  22.  
  23.  
  24. CTX_Begin_Namespace_MacOS
  25.  
  26.  
  27. /*******************************************************************
  28.     GLOBALS
  29. *******************************************************************/
  30.  
  31. const TAEDescriptor<Boolean>                kAETrueDescriptor(true);
  32. const TAEDescriptor<Boolean>                kAEFalseDescriptor(false);
  33. const TAEDescriptor<ProcessSerialNumber>    kAEThisProcessDescriptor(kCurrentProcessPSN);
  34.  
  35. /*******************************************************************
  36.     AEDescriptor
  37. *******************************************************************/
  38.  
  39. #pragma mark AEDescriptor
  40.  
  41. /*------------------------------------------------------------------
  42.     AEDescriptor
  43.     
  44.     This is a constructor for this class. It creates a copy of the
  45.     specified descriptor.
  46.     
  47.     Parameters:
  48.         In:        inAEDesc    - the descriptor to copy
  49.         Out:    (return)    - non-zero indicates an error
  50. ------------------------------------------------------------------*/
  51.  
  52. AEDescriptor::AEDescriptor(const AEDesc & inAEDesc)
  53. {
  54.     OSErr status;
  55.     status = ::AEDuplicateDesc(&inAEDesc, this);
  56.     require (status == noErr, FailedToCreateDesc);
  57.     
  58.     return;
  59.  
  60. FailedToCreateDesc:
  61.     descriptorType = typeNull;
  62.     dataHandle = NULL;
  63.     return;
  64. }
  65.  
  66.  
  67. /*------------------------------------------------------------------
  68.     AEDescriptor
  69.     
  70.     This is a constructor for this class. It creates a descriptor
  71.     of the specified type from the given data.
  72.     
  73.     Parameters:
  74.         In:        inData        - the data to copy
  75.                 inSize        - the size of the data
  76.                 inDataType    - the type of descriptor to create
  77.         Out:    (return)    - non-zero indicates an error
  78. ------------------------------------------------------------------*/
  79.  
  80. AEDescriptor::AEDescriptor(    DescType        inDataType,
  81.                             const void *    inData,
  82.                             Size            inSize)
  83. {
  84.     OSErr status;
  85.     status = ::AECreateDesc(inDataType, inData, inSize, this);
  86.     require (status == noErr, FailedToCreateDesc);
  87.     
  88.     return;
  89.  
  90. FailedToCreateDesc:
  91.     descriptorType = typeNull;
  92.     dataHandle = NULL;
  93.     return;
  94. }
  95.  
  96.  
  97. /*------------------------------------------------------------------
  98.     AEDescriptor
  99.     
  100.     This is a constructor for this class. It creates a descriptor
  101.     of the specified type from a handle to the given data.
  102.     
  103.     Parameters:
  104.         In:        inData        - the handle to the data to copy
  105.                 inDataType    - the type of descriptor to create
  106. ------------------------------------------------------------------*/
  107.  
  108. AEDescriptor::AEDescriptor(    DescType    inDataType,
  109.                                 Handle        inData)
  110. {
  111.     OSErr status;
  112.     status = CTX_MacOS::AECreateHandleDesc(inDataType, inData, this);
  113.     require (status == noErr, FailedToCreateDesc);
  114.     
  115.     return;
  116.  
  117. FailedToCreateDesc:
  118.     descriptorType = typeNull;
  119.     dataHandle = NULL;
  120.     return;
  121. }
  122.  
  123.  
  124. /*------------------------------------------------------------------
  125.     AEDescriptor
  126.     
  127.     This is a constructor for this class. It creates a "typeType"
  128.     descriptor of the specified type.
  129.     
  130.     Parameters:
  131.         In:        inData        - the type of the type descriptor to create
  132. ------------------------------------------------------------------*/
  133.  
  134. AEDescriptor::AEDescriptor(    DescType inDataType )
  135. {
  136.     OSErr status;
  137.     status = ::AECreateDesc(typeType, &inDataType, sizeof( DescType ), this);
  138.     require (status == noErr, FailedToCreateDesc);
  139.     
  140.     return;
  141.  
  142. FailedToCreateDesc:
  143.     descriptorType = typeNull;
  144.     dataHandle = NULL;
  145. }
  146.  
  147.  
  148. /*------------------------------------------------------------------
  149.     Assign
  150.     
  151.     This method makes this object a copy of inAEDesc
  152.     
  153.     Parameters:
  154.         In:        inAEDesc    - the descriptor to copy
  155.         Out:    (return)    - non-zero indicates an error
  156. ------------------------------------------------------------------*/
  157.  
  158. OSErr
  159. AEDescriptor::AssignDesc(const AEDesc & inAEDesc)
  160. {
  161.     if (descriptorType != typeNull)
  162.         ::AEDisposeDesc(this);
  163.     return ::AEDuplicateDesc(&inAEDesc, this);
  164. }
  165.  
  166.  
  167. /*------------------------------------------------------------------
  168.     Assign
  169.     
  170.     This method makes this object a descriptor of the specified
  171.     type using from the specified data.
  172.     
  173.     Parameters:
  174.         In:        inData        - the data to copy
  175.                 inSize        - the size of the data
  176.                 inDataType    - the type of descriptor to create
  177.         Out:    (return)    - non-zero indicates an error
  178. ------------------------------------------------------------------*/
  179.  
  180. OSErr
  181. AEDescriptor::Assign(    DescType        inDataType,
  182.                         const void *    inData,
  183.                         Size            inSize)
  184. {
  185.     if (descriptorType != typeNull)
  186.         ::AEDisposeDesc(this);
  187.     return ::AECreateDesc(inDataType, inData, inSize, this);
  188. }
  189.  
  190. /*------------------------------------------------------------------
  191.     Assign
  192.     
  193.     This method makes this object a descriptor of the specified
  194.     type using the data in the handle.
  195.     
  196.     Parameters:
  197.         In:        inHandle    - the handle to the data to copy
  198.                 inDataType    - the type of descriptor to create
  199.         Out:    (return)    - non-zero indicates an error
  200. ------------------------------------------------------------------*/
  201.  
  202. OSErr
  203. AEDescriptor::Assign(    DescType    inDataType,
  204.                         Handle        inData)
  205. {
  206.     if (descriptorType != typeNull)
  207.         ::AEDisposeDesc(this);
  208.     return CTX_MacOS::AECreateHandleDesc(inDataType, inData, this);
  209. }
  210.  
  211.  
  212. /*------------------------------------------------------------------
  213.     GetCString
  214.     
  215.     This method gets the descriptor data formatted as a C string.
  216.     The data is coerced to typeText if necessary.
  217.     
  218.     Parameters:
  219.         In:        inMaxLength    - the size of the output buffer
  220.         Out:    outCString    - a C string
  221.                 (return)    - non-zero indicates an error
  222. ------------------------------------------------------------------*/
  223.  
  224. OSErr
  225. AEDescriptor::GetCString(    char *    outCString,
  226.                             Size    inMaxLength) const
  227. {
  228.     OSErr status;
  229.     Size length = inMaxLength;
  230.     
  231.     if (descriptorType == typeText)
  232.     {
  233.         length = Min32(GetDataSize(), inMaxLength);
  234.         status = GetData(typeText, outCString, length);
  235.     }
  236.     else
  237.     {
  238.         AEDescriptor coercedValue;
  239.         status = CoerceToDesc(typeText, coercedValue);
  240.         require (status == noErr, FailedToCoerceDesc);
  241.         
  242.         length = Min32(coercedValue.GetDataSize(), inMaxLength);
  243.         status = coercedValue.GetData(typeText, outCString, length);
  244.  
  245.     FailedToCoerceDesc:
  246.         ;
  247.     }
  248.  
  249.     if (status == noErr && length < inMaxLength)
  250.         outCString[length] = 0;
  251.  
  252.     return status;
  253. }
  254.  
  255. /*------------------------------------------------------------------
  256.     GetPString
  257.     
  258.     This method gets the descriptor data formatted as a C string.
  259.     The data is coerced to typeText if necessary.
  260.     
  261.     Parameters:
  262.         In:        inMaxLength    - the maximum pascal string length
  263.         Out:    outPString    - a Pascal string
  264.                 (return)    - non-zero indicates an error
  265. ------------------------------------------------------------------*/
  266.  
  267. OSErr
  268. AEDescriptor::GetPString(    StringPtr    outPString,
  269.                             Size        inMaxLength) const
  270. {
  271.     OSErr status;
  272.     Size length = inMaxLength;
  273.     
  274.     if (descriptorType == typeText)
  275.     {
  276.         length = Min32(GetDataSize(), inMaxLength);
  277.         status = GetData(typeText, outPString + 1, length);
  278.     }
  279.     else
  280.     {
  281.         AEDescriptor coercedValue;
  282.         status = CoerceToDesc(typeText, coercedValue);
  283.         require (status == noErr, FailedToCoerceDesc);
  284.         
  285.         length = Min32(coercedValue.GetDataSize(), inMaxLength);
  286.         status = coercedValue.GetData(typeText, outPString + 1, length);
  287.  
  288.     FailedToCoerceDesc:
  289.         ;
  290.     }
  291.  
  292.     if (status == noErr)
  293.         outPString[0] = length;
  294.  
  295.     return status;
  296. }
  297.  
  298. /*******************************************************************
  299.     AEDescriptorList
  300. *******************************************************************/
  301.  
  302. #pragma mark -
  303. #pragma mark AEDescriptorList
  304.  
  305. /*------------------------------------------------------------------
  306.     AEDescriptorList
  307.     
  308.     This is a constructor for this class.
  309.     
  310.     Parameters:
  311.         In:        inFactoringPtr    - a pointer to data at the beggining
  312.                                   of each descriptor that is the
  313.                                   same for all elements of the list
  314.                 inSize            - the size of the above data
  315. ------------------------------------------------------------------*/
  316.  
  317. AEDescriptorList::AEDescriptorList(    const void *    inFactoringPtr,
  318.                                         Size            inSize)
  319. {
  320.     OSErr status;
  321.     status = ::AECreateList(inFactoringPtr, inSize, false, this);
  322.     require (status == noErr, FailedToCreateDesc);
  323.     
  324.     return;
  325.  
  326. FailedToCreateDesc:
  327.     descriptorType = typeNull;
  328.     dataHandle = NULL;
  329.     return;
  330. }
  331.  
  332. /*------------------------------------------------------------------
  333.     AEDescriptorList
  334.     
  335.     This is the copy constructor for this class.
  336.     
  337.     Parameters:
  338.         In:        inOriginal    - the descriptor list to copy
  339. ------------------------------------------------------------------*/
  340.  
  341. AEDescriptorList::AEDescriptorList(const AEDesc & inOriginal)
  342. {
  343.     require (inOriginal.descriptorType == typeAEList, OriginalNotAList);
  344.     
  345.     OSErr status;
  346.     status = ::AEDuplicateDesc(&inOriginal, this);
  347.     require (status == noErr, FailedToDuplicateDesc);
  348.  
  349.     return;
  350.  
  351. FailedToDuplicateDesc:    
  352. OriginalNotAList:
  353.     descriptorType = typeNull;
  354.     dataHandle = NULL;
  355.     return;
  356. }
  357.  
  358.  
  359. /*------------------------------------------------------------------
  360.     AEDescriptorList
  361.     
  362.     This is the copy constructor for this class.
  363.     
  364.     Parameters:
  365.         In:        inOriginal    - the descriptor list to copy
  366. ------------------------------------------------------------------*/
  367.  
  368. AEDescriptorList::AEDescriptorList(const AEDescriptorList & inOriginal)
  369. {
  370.     OSErr status;
  371.     status = ::AEDuplicateDesc(&inOriginal, this);
  372.     require (status == noErr, FailedToDuplicateDesc);
  373.  
  374.     return;
  375.  
  376. FailedToDuplicateDesc:    
  377. OriginalNotAList:
  378.     descriptorType = typeNull;
  379.     dataHandle = NULL;
  380.     return;
  381. }
  382.  
  383.  
  384. /*------------------------------------------------------------------
  385.     PutCStringItem
  386.     
  387.     This method adds an item or sets the specified item's data to
  388.     the C string.
  389.     
  390.     Parameters:
  391.         In:        inCString    - the C string
  392.                 inIndex        - the index of the item to set; 0 appends
  393.                                 a new item to the list
  394.         Out:    (return)    - non-zero indicates an error
  395. ------------------------------------------------------------------*/
  396.  
  397. OSErr
  398. AEDescriptorList::PutCStringItem(    const char *    inCString,
  399.                                     SInt32            inIndex)
  400. {
  401.     AEDescriptor string(typeText, inCString, std::strlen(inCString));
  402.     require (string.descriptorType != typeNull, FailedToCreateDesc);
  403.  
  404.     return PutItemDesc(string, inIndex);
  405.  
  406. FailedToCreateDesc:
  407.     return memFullErr;
  408. }
  409.  
  410. /*------------------------------------------------------------------
  411.     PutPStringItem
  412.     
  413.     This method adds an item or sets the specified item's data to
  414.     the P string.
  415.     
  416.     Parameters:
  417.         In:        inPString    - the Pascal string
  418.                 inIndex        - the index of the item to set; 0 appends
  419.                                 a new item to the list
  420.         Out:    (return)    - non-zero indicates an error
  421. ------------------------------------------------------------------*/
  422.  
  423. OSErr
  424. AEDescriptorList::PutPStringItem(    ConstStringPtr    inPString,
  425.                                     SInt32            inIndex)
  426. {
  427.     AEDescriptor string(typeText, inPString + 1, StrLength(inPString));
  428.     require (string.descriptorType != typeNull, FailedToCreateDesc);
  429.  
  430.     return PutItemDesc(string, inIndex);
  431.  
  432. FailedToCreateDesc:
  433.     return memFullErr;
  434. }
  435.  
  436. /*------------------------------------------------------------------
  437.     PutBooleanItem
  438.     
  439.     This method adds an item or sets the specified item's data to
  440.     the boolean value.
  441.     
  442.     Parameters:
  443.         In:        inBool        - the boolean value
  444.                 inIndex        - the index of the item to set; 0 appends
  445.                                 a new item to the list
  446.         Out:    (return)    - non-zero indicates an error
  447. ------------------------------------------------------------------*/
  448.  
  449. OSErr
  450. AEDescriptorList::PutBooleanItem(    Boolean        inBool,
  451.                                     SInt32        inIndex)
  452. {
  453.     AEDescriptor boolItem(typeBoolean, &inBool, sizeof(inBool));
  454.     require (boolItem.descriptorType != typeNull, FailedToCreateDesc);
  455.     
  456.     return PutItemDesc(boolItem, inIndex);
  457.     
  458. FailedToCreateDesc:
  459.     return memFullErr;
  460. }
  461.  
  462.  
  463. /*------------------------------------------------------------------
  464.     GetCStringItem
  465.     
  466.     This method gets the nth item as a C string.
  467.     
  468.     Parameters:
  469.         In:        inIndex        - the index of the item to get; the
  470.                                 first item starts with 1
  471.                 inMaxLength    - the size of the output buffer
  472.         Out:    outCString    - a C string
  473.                 (return)    - non-zero indicates an error
  474. ------------------------------------------------------------------*/
  475.  
  476. OSErr
  477. AEDescriptorList::GetCStringItem(    SInt32        inIndex,
  478.                                     char *        outCString,
  479.                                     Size        inMaxLength)
  480. {
  481.     OSErr status;
  482.  
  483.     AEDescriptor itemDesc;
  484.     status = GetItemDesc(inIndex, typeWildCard, itemDesc);
  485.     require (status == noErr, FailedToGetItem);
  486.     
  487.     status = itemDesc.GetCString(outCString, inMaxLength);
  488.  
  489. FailedToGetItem:
  490.     return status;
  491. }
  492.  
  493. /*------------------------------------------------------------------
  494.     GetPStringItem
  495.     
  496.     This method gets the nth item as a Pascal string.
  497.     
  498.     Parameters:
  499.         In:        inIndex        - the index of the item to get; the
  500.                                 first item starts with 1
  501.                 inMaxLength    - the size of the output buffer
  502.         Out:    outPString    - a Pascal string
  503.                 (return)    - non-zero indicates an error
  504. ------------------------------------------------------------------*/
  505.  
  506. OSErr
  507. AEDescriptorList::GetPStringItem(    SInt32        inIndex,
  508.                                     StringPtr    outPString,
  509.                                     Size        inMaxLength)
  510. {
  511.     OSErr status;
  512.  
  513.     AEDescriptor itemDesc;
  514.     status = GetItemDesc(inIndex, typeWildCard, itemDesc);
  515.     require (status == noErr, FailedToGetItem);
  516.     
  517.     status = itemDesc.GetPString(outPString, inMaxLength);
  518.  
  519. FailedToGetItem:
  520.     return status;
  521. }
  522.  
  523.  
  524. /*------------------------------------------------------------------
  525.     GetBooleanItem
  526.     
  527.     This method gets the nth item as a boolean value.
  528.     
  529.     Parameters:
  530.         In:        inIndex        - the index of the item to get; the
  531.                                 first item starts with 1
  532.         Out:    outBoolean    - a Boolean value
  533.                 (return)    - non-zero indicates an error
  534. ------------------------------------------------------------------*/
  535.  
  536. OSErr
  537. AEDescriptorList::GetBooleanItem(    SInt32        inIndex,
  538.                                     Boolean&    outBoolean)
  539. {
  540.     OSErr status;
  541.  
  542.     AEDescriptor itemDesc;
  543.     status = GetItemDesc(inIndex, typeWildCard, itemDesc);
  544.     require (status == noErr, FailedToGetItem);
  545.     
  546.     status = itemDesc.GetData( typeBoolean, outBoolean );
  547.  
  548. FailedToGetItem:
  549.     return status;
  550. }
  551.  
  552.  
  553. /*******************************************************************
  554.     AEDescriptorRecord
  555. *******************************************************************/
  556.  
  557. #pragma mark -
  558. #pragma mark AEDescriptorRecord
  559.  
  560. /*------------------------------------------------------------------
  561.     AEDescriptorRecord
  562.     
  563.     This is a constructor for this class.
  564.     
  565.     Parameters:
  566.         In:        inFactoringPtr    - a pointer to data at the beggining
  567.                                   of each descriptor that is the
  568.                                   same for all elements of the list
  569.                 inSize            - the size of the above data
  570. ------------------------------------------------------------------*/
  571.  
  572. AEDescriptorRecord::AEDescriptorRecord(    const void *    inFactoringPtr,
  573.                                             Size            inSize)
  574. {
  575.     OSErr status;
  576.     status = ::AECreateList(inFactoringPtr, inSize, true, this);
  577.     require (status == noErr, FailedToCreateDesc);
  578.     
  579.     return;
  580.  
  581. FailedToCreateDesc:
  582.     descriptorType = typeNull;
  583.     dataHandle = NULL;
  584.     return;
  585. }
  586.  
  587. /*------------------------------------------------------------------
  588.     AEDescriptorRecord
  589.     
  590.     This is the copy constructor for this class.
  591.     
  592.     Parameters:
  593.         In:        inOriginal    - the record descriptor to copy
  594. ------------------------------------------------------------------*/
  595.  
  596. AEDescriptorRecord::AEDescriptorRecord(const AEDesc & inOriginal)
  597. {
  598.     require (inOriginal.descriptorType == typeAERecord, OriginalNotARecord);
  599.     
  600.     OSErr status;
  601.     status = ::AEDuplicateDesc(&inOriginal, this);
  602.     require (status == noErr, FailedToDuplicateDesc);
  603.  
  604.     return;
  605.  
  606. FailedToDuplicateDesc:    
  607. OriginalNotARecord:
  608.     descriptorType = typeNull;
  609.     dataHandle = NULL;
  610.     return;
  611. }
  612.  
  613.  
  614. /*------------------------------------------------------------------
  615.     AEDescriptorRecord
  616.     
  617.     This is the copy constructor for this class.
  618.     
  619.     Parameters:
  620.         In:        inOriginal    - the record descriptor to copy
  621. ------------------------------------------------------------------*/
  622.  
  623. AEDescriptorRecord::AEDescriptorRecord(const AEDescriptorRecord & inOriginal)
  624. {
  625.     OSErr status;
  626.     status = ::AEDuplicateDesc(&inOriginal, this);
  627.     require (status == noErr, FailedToDuplicateDesc);
  628.  
  629.     return;
  630.  
  631. FailedToDuplicateDesc:    
  632.     descriptorType = typeNull;
  633.     dataHandle = NULL;
  634.     return;
  635. }
  636.  
  637.  
  638. /*------------------------------------------------------------------
  639.     PutCStringKey
  640.     
  641.     This method sets the specified keywords's data to the C string.
  642.     
  643.     Parameters:
  644.         In:        inKey        - the keyword
  645.                 inCString    - the C string
  646.         Out:    (return)    - non-zero indicates an error
  647. ------------------------------------------------------------------*/
  648.  
  649. OSErr
  650. AEDescriptorRecord::PutCStringKey(    AEKeyword        inKey,
  651.                                     const char *    inCString)
  652. {
  653.     AEDescriptor string(typeText, inCString, std::strlen(inCString));
  654.     require (string.descriptorType != typeNull, FailedToCreateDesc);
  655.  
  656.     return PutKeyDesc(inKey, string);
  657.  
  658. FailedToCreateDesc:
  659.     return memFullErr;
  660. }
  661.  
  662. /*------------------------------------------------------------------
  663.     PutPStringKey
  664.     
  665.     This method sets the specified keywords's data to the Pascal string.
  666.     
  667.     Parameters:
  668.         In:        inKey        - the keyword
  669.                 inPString    - the Pascal string
  670.         Out:    (return)    - non-zero indicates an error
  671. ------------------------------------------------------------------*/
  672.  
  673. OSErr
  674. AEDescriptorRecord::PutPStringKey(    AEKeyword        inKey,
  675.                                     ConstStringPtr    inPString)
  676. {
  677.     AEDescriptor string(typeText, inPString + 1, StrLength(inPString));
  678.     require (string.descriptorType != typeNull, FailedToCreateDesc);
  679.  
  680.     return PutKeyDesc(inKey, string);
  681.  
  682. FailedToCreateDesc:
  683.     return memFullErr;
  684. }
  685.  
  686. /*------------------------------------------------------------------
  687.     GetCStringKey
  688.     
  689.     This method gets the keyword data as a C string.
  690.     
  691.     Parameters:
  692.         In:        inKey        - the keyword
  693.                 inMaxLength    - the size of the output buffer
  694.         Out:    outCString    - a C string
  695.                 (return)    - non-zero indicates an error
  696. ------------------------------------------------------------------*/
  697.  
  698. OSErr
  699. AEDescriptorRecord::GetCStringKey(    AEKeyword    inKey,
  700.                                     char *        outCString,
  701.                                     Size        inMaxLength)
  702. {
  703.     OSErr status;
  704.  
  705.     AEDescriptor itemDesc;
  706.     status = GetKeyDesc(inKey, typeWildCard, itemDesc);
  707.     require (status == noErr, FailedToGetKey);
  708.     
  709.     status = itemDesc.GetCString(outCString, inMaxLength);
  710.  
  711. FailedToGetKey:
  712.     return status;
  713. }
  714.  
  715. /*------------------------------------------------------------------
  716.     GetCStringKey
  717.     
  718.     This method gets the keyword data as a Pascal string.
  719.     
  720.     Parameters:
  721.         In:        inKey        - the keyword
  722.                 inMaxLength    - the size of the output buffer
  723.         Out:    outPString    - a Pascal string
  724.                 (return)    - non-zero indicates an error
  725. ------------------------------------------------------------------*/
  726.  
  727. OSErr
  728. AEDescriptorRecord::GetPStringKey(    AEKeyword    inKey,
  729.                                     StringPtr    outPString,
  730.                                     Size        inMaxLength)
  731. {
  732.     OSErr status;
  733.  
  734.     AEDescriptor itemDesc;
  735.     status = GetKeyDesc(inKey, typeWildCard, itemDesc);
  736.     require (status == noErr, FailedToGetKey);
  737.     
  738.     status = itemDesc.GetPString(outPString, inMaxLength);
  739.  
  740. FailedToGetKey:
  741.     return status;
  742. }
  743.  
  744. /*******************************************************************
  745.     AEObjSpecifier
  746. *******************************************************************/
  747.  
  748. #pragma mark -
  749. #pragma mark AEObjSpecifier
  750.  
  751. /*------------------------------------------------------------------
  752.     AEObjSpecifier
  753.     
  754.     This is a constructor for this class. It builds an object
  755.     specifier record given the following parameters:
  756.     
  757.     Parameters:
  758.         In:        inDesiredClass    - the class of the object
  759.                 inKeyForm        - the key form
  760.                 inKeyData        - the key data
  761.                 inContainer        - the object container
  762. ------------------------------------------------------------------*/
  763.  
  764. AEObjSpecifier::AEObjSpecifier(
  765.     DescType        inDesiredClass,
  766.     DescType        inKeyForm,
  767.     const AEDesc&    inKeyData,
  768.     const AEDesc&    inContainer)
  769.     : AEDescriptorRecord(kAESuppressCreate)
  770. {
  771.     OSErr status;
  772.     status = ::CreateObjSpecifier(
  773.         inDesiredClass,
  774.         const_cast<AEDesc*>(&inContainer),
  775.         inKeyForm,
  776.         const_cast<AEDesc*>(&inKeyData),
  777.         false,
  778.         this);
  779.     require (status == noErr, FailedToCreateObjectSpecifier);
  780.     
  781.     return;
  782.  
  783. FailedToCreateObjectSpecifier:
  784.     descriptorType = typeNull;
  785.     dataHandle = NULL;
  786.     return;
  787. }
  788.  
  789. /*******************************************************************
  790.     AEAppleEvent
  791. *******************************************************************/
  792.  
  793. #pragma mark -
  794. #pragma mark AEAppleEvent
  795.  
  796. /*------------------------------------------------------------------
  797.     AEAppleEvent
  798.     
  799.     This is a constructor for this class. It builds an AppleEvent
  800.     record given the following parameters:
  801.     
  802.     Parameters:
  803.         In:        inAEClass        - the event class
  804.                 inAEEventID        - the event ID
  805.                 inTarget        - the receipient's PSN
  806.                 inReturnID        - the return ID of the event
  807.                 inTransactionID    - the transaction ID of the event
  808. ------------------------------------------------------------------*/
  809.  
  810. AEAppleEvent::AEAppleEvent(
  811.     AEEventClass                inAEClass,
  812.     AEEventID                    inAEEventID,
  813.     const ProcessSerialNumber&    inTarget,
  814.     AEReturnID                    inReturnID,
  815.     AETransactionID                inTransactionID)
  816.     : AEDescriptorRecord(kAESuppressCreate)
  817. {
  818.     TAEDescriptor<ProcessSerialNumber> targetDesc(inTarget);
  819.     MakeAppleEvent(inAEClass, inAEEventID, targetDesc, inReturnID, inTransactionID);
  820. }
  821.  
  822. /*------------------------------------------------------------------
  823.     AEAppleEvent
  824.     
  825.     This is a constructor for this class. It builds an AppleEvent
  826.     record given the following parameters:
  827.     
  828.     Parameters:
  829.         In:        inAEClass        - the event class
  830.                 inAEEventID        - the event ID
  831.                 inTarget        - the receipient's application
  832.                                   signature
  833.                 inReturnID        - the return ID of the event
  834.                 inTransactionID    - the transaction ID of the event
  835. ------------------------------------------------------------------*/
  836.  
  837. AEAppleEvent::AEAppleEvent(
  838.     AEEventClass    inAEClass,
  839.     AEEventID        inAEEventID,
  840.     OSType            inTarget,
  841.     AEReturnID        inReturnID,
  842.     AETransactionID    inTransactionID)
  843.     : AEDescriptorRecord(kAESuppressCreate)
  844. {
  845.     TAEDescriptor<OSType> targetDesc(typeApplSignature, inTarget);
  846.     MakeAppleEvent(inAEClass, inAEEventID, targetDesc, inReturnID, inTransactionID);
  847. }
  848.  
  849. /*------------------------------------------------------------------
  850.     AEAppleEvent
  851.     
  852.     This is a copy constructor for this class.
  853.     
  854.     Parameters:
  855.         In:        inOriginal    - the original AEDesc to copy
  856. ------------------------------------------------------------------*/
  857.  
  858. AEAppleEvent::AEAppleEvent(const AEDesc & inOriginal)
  859. {
  860.     require (inOriginal.descriptorType == typeAppleEvent, OriginalNotAnAppleEvent);
  861.     
  862.     OSErr status;
  863.     status = ::AEDuplicateDesc(&inOriginal, this);
  864.     require (status == noErr, FailedToDuplicateDesc);
  865.  
  866.     return;
  867.  
  868. FailedToDuplicateDesc:    
  869. OriginalNotAnAppleEvent:
  870.     descriptorType = typeNull;
  871.     dataHandle = NULL;
  872.     return;
  873. }
  874.  
  875. /*------------------------------------------------------------------
  876.     AEAppleEvent
  877.     
  878.     This is a copy constructor for this class.
  879.     
  880.     Parameters:
  881.         In:        inOriginal    - the original object to copy
  882. ------------------------------------------------------------------*/
  883.  
  884. AEAppleEvent::AEAppleEvent(const AEAppleEvent & inOriginal)
  885. {
  886.     OSErr status;
  887.     status = ::AEDuplicateDesc(&inOriginal, this);
  888.     require (status == noErr, FailedToDuplicateDesc);
  889.  
  890.     return;
  891.  
  892. FailedToDuplicateDesc:    
  893. OriginalNotAnAppleEvent:
  894.     descriptorType = typeNull;
  895.     dataHandle = NULL;
  896.     return;
  897. }
  898.  
  899.  
  900. /*------------------------------------------------------------------
  901.     AEAppleEvent
  902.     
  903.     This is a default constructor for this class. It is intended
  904.     to be used for declaring an AppleEvent to hold a reply,
  905.     because it does not actually create an AppleEvent.
  906.     
  907.     Parameters: none
  908. ------------------------------------------------------------------*/
  909.  
  910. AEAppleEvent::AEAppleEvent()
  911. {
  912.     descriptorType = typeNull;
  913.     dataHandle = NULL;
  914. }
  915.  
  916.  
  917. /*------------------------------------------------------------------
  918.     FinishCreate
  919.     
  920.     This is a common routine used by the various constructors.
  921.     
  922.     Parameters:
  923.         In:        inAEClass        - the event class
  924.                 inAEEventID        - the event ID
  925.                 inTarget        - the receipient of the AppleEvent
  926.                 inReturnID        - the return ID of the event
  927.                 inTransactionID    - the transaction ID of the event
  928. ------------------------------------------------------------------*/
  929.  
  930. void
  931. AEAppleEvent::MakeAppleEvent(
  932.     AEEventClass    inAEClass,
  933.     AEEventID        inAEEventID,
  934.     const AEDesc&    inTarget,
  935.     AEReturnID        inReturnID,
  936.     AETransactionID    inTransactionID)
  937. {
  938.     OSErr status;
  939.     status = ::AECreateAppleEvent(inAEClass, inAEEventID,
  940.                                         &inTarget, inReturnID, inTransactionID, this);
  941.     require (status == noErr, FailedToCreateAppleEvent);
  942.  
  943.     return;
  944.  
  945. FailedToCreateAppleEvent:
  946.     descriptorType = typeNull;
  947.     dataHandle = NULL;
  948.     return;
  949. }
  950.  
  951.  
  952. CTX_End_Namespace_MacOS
  953.  
  954.  
  955. /*==================================================================
  956.     Change History (most recent first):
  957.  
  958.     $Log: MacOS_UAppleEvents.cpp,v $
  959. ==================================================================*/
  960.